package com.stedu.service.impl;

import com.stedu.bean.Models;
import com.stedu.exception.SteduException;
import com.stedu.mapper.CarsMapper;
import com.stedu.mapper.ModelsMapper;
import com.stedu.service.ModelsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class ModelsServiceImpl implements ModelsService {
    @Autowired
    private ModelsMapper modelsMapper;
    @Autowired
    private CarsMapper carsMapper;
    //添加
    @Override
    public boolean insert(Models m) throws SteduException {

    return modelsMapper.insert(m)==1;
    }
    //删除
    @Override
    public boolean delete(Integer mid) throws SteduException {
        //车辆表中有该车型不允许删除
        if (carsMapper.selectByMid(mid)!=null){
            throw new SteduException("该车型还有车辆，无法删除");
        }
       return modelsMapper.delete(mid) == 1;
    }
//修改
    @Override
    public boolean update(Models m) throws SteduException {
     return  modelsMapper.update(m)==1;
    }

    @Override
    public Models selectByMid(Integer mid) {
        return  modelsMapper.selectByMid(mid);
    }

    @Override
    public List<Models> selectAll() {
        return modelsMapper.selectAll();
    }
}
